#include "Selection.h"
#include <iostream>


using namespace sf;

Selection::Selection(sf::RenderWindow &window) :
myWindow(window)


{
	if (!font.loadFromFile("PlaneCrash.ttf"))
	{
		
	}
	//---------------------Clavier1---------------------------
	clavier1.setFont(font);
	clavier1.setString("green soldier");
	clavier1.setCharacterSize(30);
	clavier1.setColor(sf::Color::Green);
	clavier1.setPosition(50, 200);

	//---------------------Clavier2---------------------------
	clavier2.setFont(font);
	clavier2.setString("red soldier");
	clavier2.setCharacterSize(30);
	clavier2.setColor(sf::Color::Red);
	clavier2.setPosition(450, 200);

	//---------------------manette1---------------------------
	manette1.setFont(font);
	manette1.setString("blue soldier");
	manette1.setCharacterSize(30);
	manette1.setColor(sf::Color::Blue);
	manette1.setPosition(50, 400);

	//---------------------manette2---------------------------
	manette2.setFont(font);
	manette2.setString("yellow soldier");
	manette2.setCharacterSize(30);
	manette2.setColor(sf::Color::Yellow);
	manette2.setPosition(450, 400);

	//-----------------TITRE--------------------
	myTitle.setFont(font);
	myTitle.setString("who plays?");
	myTitle.setCharacterSize(60);
	myTitle.setColor(sf::Color::Red);
	myTitle.setPosition(150, 40);

	//------------------TIME---------------------
	myTime.setFont(font);
	myTime.setCharacterSize(60);
	myTime.setColor(sf::Color::Red);
	myTime.setPosition(350, 300);

	//-----------------Background--------------------

	if (!backgroundSelectionText.loadFromFile("./MenuBackground.jpg"))
	{
		// erreur MenuBackground
	}


	backgroundSelectionSprite.setTexture(backgroundSelectionText);

	backgroundSelectionSprite.setPosition(0, 0);
	
	c1 = false;
	c2 = false;
	m1 = false;
	m2 = false;

}

void Selection::setC1(bool b)
{
	c1 = b;
}

void Selection::setC2(bool b)
{
	c2 = b;
}

void Selection::setM1(bool b)
{
	m1 = b;
}

void Selection::setM2(bool b)
{
	m2 = b;
}

Selection::~Selection()
{


}

void Selection::selectionReset()
{
	c1 = false; 
	c2 = false;
	m1 = false;
	m2 = false;
}



void Selection::displaySelection(Clock clock)
{
	myWindow.draw(backgroundSelectionSprite);
	myWindow.draw(myTitle);
	if (c1)
		myWindow.draw(clavier1);
	if (c2)
		myWindow.draw(clavier2);
	if (m1)
		myWindow.draw(manette1);
	if (m2)
		myWindow.draw(manette2);
	//---------------------TIME-------------------------

	if (clock.getElapsedTime().asSeconds() < 1)
	{
		myTime.setString("5");
	}
	else if (clock.getElapsedTime().asSeconds() < 2)
	{
		myTime.setString("4");
	}
	else if (clock.getElapsedTime().asSeconds() < 3)
	{
		myTime.setString("3");
	}
	else if (clock.getElapsedTime().asSeconds() < 4)
	{
		myTime.setString("2");
	}
	else
	{
		myTime.setString("1");
	}
	
	myWindow.draw(myTime);
}

void Selection::initSelection(){



}

void Selection::playAudio(){


	if (!bufferBackground.loadFromFile("cliclac.wav"))
		return;

	soundBackground.setBuffer(bufferBackground);
	soundBackground.setLoop(true);
	soundBackground.play();

}

void Selection::playAudioSelection(){
	if (!bufferSelector.loadFromFile("selector.wav"))
		return;

	soundSelector.setBuffer(bufferSelector);
	soundSelector.setVolume(25);
	soundSelector.play();


}
void Selection::closeWindow(){

	myWindow.close();

}

void Selection::stopAudio(){


	soundBackground.stop();

}